﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace TaiwuZD
{
    public class TwBuilding :TwObject
    { 

        /// <summary>
        /// 类型
        /// 0空地 资源
        /// 1建筑
        /// </summary>
        public int Category { get; set; }



        private int _Level;
        /// <summary>
        /// 等级
        /// </summary> 
        public int Level
        {
            get { return _Level; }
            set { SetProperty(ref _Level, value); }
        }


        /// <summary>
        /// 用处
        /// </summary>
        public string Usage { get { return this[100]; } }
        
        /// <summary>
        /// 建筑对应类型，和生活技能相关
        /// </summary>
        public int BuildingType
        {
            get
            {
                if (Id > 1 && Id <= 110)
                    return 0;
                else if (Id > 10000 && Id < 20000)
                    return 1;
                else if (Id >= 1002 & Id <= 1007)
                    return 2;
                else if (Id > 2000)
                    return (Id - 2000) / 100 + 3;
                else
                    return -1;
            }
        }

       

        public static TwBuilding Create(int id = -1, int level = 20)
        {
            if (GameAssets.TwBuildings.ContainsKey(id))
            {
                var item = GameAssets.TwBuildings[id];

                var ni = item.Copy<TwBuilding>();
                ni.Level = level;

                return ni;
            }
            else
                return new TwBuilding { Name = "空地" };
        }

        public override object Clone()
        {
            return Create(Id);
        }

        protected override string GetDefaultValue(string key)
        {
            if (GameAssets.TwBuildings != null)
            {
                if (GameAssets.TwBuildings.ContainsKey(Id))
                    if (GameAssets.TwBuildings[Id].DataShop.ContainsKey(key))
                        return GameAssets.TwBuildings[Id].DataShop[key];
            }

            return base.GetDefaultValue(key);
        }
    }


}
